package com.xdh.zzqh.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.TextView
import com.xdh.zzqh.R

class LabelTextInput(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    private val tvName: TextView
    private val et: EditText

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.view_label_textinput, this)
        tvName = view.findViewById(R.id.id_input_tv)
        et = view.findViewById(R.id.id_id_input_et)

        val attr = context.obtainStyledAttributes(attrs, R.styleable.LabelTextInput)
        val name = attr.getString(R.styleable.LabelTextInput_lti_name) ?: ""
        val def = attr.getString(R.styleable.LabelTextInput_lti_def) ?: ""
        attr.recycle()
        tvName.text = name
        et.setText(def)
    }

    fun setName(name: String) {
        tvName.text = name
    }

    fun text() = et.text.toString()

    fun setText(text: String) {
        et.setText(text)
    }
}